﻿using System;
using UnityEngine;

// Token: 0x02000126 RID: 294
[AddComponentMenu("RVP/C#/Drivetrain/Transmission/Continuous Transmission", 1)]
[DisallowMultipleComponent]
public class ContinuousTransmission : Transmission
{
	// Token: 0x0600056C RID: 1388 RVA: 0x00029C7C File Offset: 0x00027E7C
	private void FixedUpdate()
	{
		this.health = Mathf.Clamp01(this.health);
		if (this.maxRPM == -1f)
		{
			this.maxRPM = this.targetDrive.curve.keys[this.targetDrive.curve.length - 1].time * 1000f;
		}
		if (this.health > 0f)
		{
			if (this.automatic && this.vp.groundedWheels > 0)
			{
				this.targetRatio = (1f - this.vp.burnout) * Mathf.Clamp01(Mathf.Abs(this.targetDrive.feedbackRPM) / Mathf.Max(0.01f, this.maxRPM * Mathf.Abs(this.currentRatio)));
			}
			else if (!this.automatic)
			{
				this.targetRatio = Mathf.Clamp01(this.targetRatio + (this.vp.upshiftHold - this.vp.downshiftHold) * this.manualShiftRate * Time.deltaTime);
			}
		}
		this.reversing = (this.canReverse && this.vp.burnout == 0f && this.vp.localVelocity.z < 1f && (this.vp.accelInput < 0f || (this.vp.brakeIsReverse && this.vp.brakeInput > 0f)));
		this.currentRatio = Mathf.Lerp(this.minRatio, this.maxRatio, this.targetRatio) * (float)((!this.reversing) ? 1 : -1);
		this.newDrive.curve = this.targetDrive.curve;
		this.newDrive.rpm = this.targetDrive.rpm / this.currentRatio;
		this.newDrive.torque = Mathf.Abs(this.currentRatio) * this.targetDrive.torque;
		base.SetOutputDrives(this.currentRatio);
	}

	// Token: 0x04000786 RID: 1926
	[Tooltip("Lerp value between min ratio and max ratio")]
	[Range(0f, 1f)]
	public float targetRatio;

	// Token: 0x04000787 RID: 1927
	public float minRatio;

	// Token: 0x04000788 RID: 1928
	public float maxRatio;

	// Token: 0x04000789 RID: 1929
	[NonSerialized]
	public float currentRatio;

	// Token: 0x0400078A RID: 1930
	public bool canReverse;

	// Token: 0x0400078B RID: 1931
	[NonSerialized]
	public bool reversing;

	// Token: 0x0400078C RID: 1932
	[Tooltip("How quickly the target ratio changes with manual shifting")]
	public float manualShiftRate = 0.5f;
}
